// drawarea.cpp

#include <QtGui>
#include "drawarea.h"
#include "mainwindow.h"


DrawArea::DrawArea(QWidget *parent) :
    QWidget(parent)
{
    setAttribute(Qt::WA_StaticContents);

    windowmaxx = 375;
    windowmaxy = 375;

    image.load(":/backgrounds/Mountains.jpeg",0);

    newprojectile = new ball;
    newlauncher = new launcher;
    ballradius = newlauncher->ReturnShaftRadius();


    // gets the origin of the ball
    QPainter temp(this);
    newlauncher->DrawLauncher(temp);
    ballorigin = newlauncher->ReturnInitBallLocation();
    newprojectile->SetRadius(ballradius*4);


    newprojectile->SetCenterPoint(ballorigin);
}

void DrawArea::paintEvent(QPaintEvent *)
{
    QPainter painter(this);

    // inits stats about the pen
    int lineThickness = 2;
    QColor lineColor = QColor(255, 255, 255, 255);
    // inits the pen
    QPen pen;
    pen.setWidth(lineThickness);
    pen.setColor(lineColor);

    //this is where stuff gets drawn
    coordconv CoordConverter(-1, 1, -1, 1, 0, windowmaxx, 0, windowmaxy, MAXX, MAXY);
    // draw background
    painter.drawImage(0, 0 , image, 0, 0, -1, -1, 0);


    // draw rings
    // draw cannon
    newlauncher->SetCoordConverter(CoordConverter);
    newlauncher->DrawLauncher(painter);

    // draw ball
    projectile::type temp;
    temp = newprojectile->getballtype();
    cout << "temp: "<<(int) temp << endl;

    newprojectile->SetCoordConverter(CoordConverter);
    newprojectile->drawprojectile(painter);

}
